<!--
产品管理—如何预定页
凌辉
2017-5-25
-->
<template>
  <el-row>
    <el-col>
      <span style="color: #20a0ff;margin-left: 20px">重要提示</span>
    </el-col>
    <el-col style="margin-top: 20px;margin-left: 20px;">
      <el-input :disabled="pageType === 'look'||pageType === 'audits'" @blur="zytsBlur" type="textarea" :rows="15" v-model="productTourExtend.zyts"
                style="width: 80%"></el-input>
      <span style="color: #f00;" v-if="noXytsNull">请输入重要提示</span>
    </el-col>
    <el-col style="margin-left: 20px;margin-top: 20px">
      <span style="color: #20a0ff;">友情提示</span>
    </el-col>
    <el-col style="margin-top: 20px;margin-left: 20px;">
      <el-input :disabled="pageType === 'look'||pageType === 'audits'" @blur="yqtsBlur" type="textarea" :rows="15" v-model="productTourExtend.yqts"
                style="width: 80%"></el-input>
      <span style="color: #f00;" v-if="noYqtsNull">请输入友情提示</span>
    </el-col>
    <el-col style="margin-top: 20px;margin-left: 20px;">
      <span style="color: #20a0ff;">退改说明</span>
    </el-col>
    <el-col style="margin-top: 20px;margin-left: 20px;">
      <el-input :disabled="pageType === 'look'||pageType === 'audits'" @blur="tgsmBlur" type="textarea" :rows="15" v-model="productTourExtend.tgsm"
                style="width: 80%"></el-input>
      <span style="color: #f00;" v-if="noTgsmNull">请输入退改说明</span>
    </el-col>
    <el-col>
      <el-button type="primary" :disabled="pageType === 'look'||pageType === 'audits'" @click="handleSubmit" style="margin-top: 20px;margin-left: 20px;" :loading="saveNextLoading">保存并下一步</el-button>
    </el-col>
  </el-row>
</template>

<script type="text/ecmascript-6">
  export default {
    props: {
      productIdConfig: {
        type: Number
      },
      pageType: {
        type: String
      }
    },
    data () {
      return {
        saveNextLoading: false,
        loginType: '',
        noXytsNull: false,
        noYqtsNull: false,
        noTgsmNull: false,
        productTourExtend: {
          productId: '',
          zyts: '',
          yqts: '',
          tgsm: ''
        }
      }
    },
    methods: {
      handleSubmit () {
        if (this.productIdConfig <= 0) {
          this.$message({
            message: '请先填写基本信息',
            type: 'error'
          })
          this.$emit('saveNext', '0')
          return
        }
        let zytsBol = this.zytsBlur()
        let yqtsBol = this.yqtsBlur()
        let tgsmBol = this.tgsmBlur()
        if (zytsBol && yqtsBol && tgsmBol) {
          this.productTourExtend.productId = this.productIdConfig
          var url = '/tour/web/productTourExtend/save.htm'
          var para = {
            productTourExtend: this.productTourExtend,
            type: this.loginType
          }
          this.saveNextLoading = true
          this.$http.post(url, para).then(response => {
            this.saveNextLoading = false
            var resBody = response.body
            if (resBody.isSuccess === 0) {
              this.$emit('saveNext', '6')
            } else if (resBody.isSuccess === 2) {
              this.listLoading = false
              this.$alert(resBody.errorMsg, ' ', {
                type: 'warning'
              }).then(() => {
                this.$router.push({path: '/login'})
                sessionStorage.clear()
              })
            } else {
              this.$message({
                showClose: true,
                message: resBody.errorMsg,
                type: 'error'
              })
            }
          })
        }
      },
      zytsBlur () {
        if (this.productTourExtend.zyts === '' || this.productTourExtend.zyts === undefined) {
          this.noXytsNull = true
          return false
        } else {
          this.noXytsNull = false
          return true
        }
      },
      yqtsBlur () {
        if (this.productTourExtend.yqts === '' || this.productTourExtend.yqts === undefined) {
          this.noYqtsNull = true
          return false
        } else {
          this.noYqtsNull = false
          return true
        }
      },
      tgsmBlur () {
        if (this.productTourExtend.tgsm === '' || this.productTourExtend.tgsm === undefined) {
          this.noTgsmNull = true
          return false
        } else {
          this.noTgsmNull = false
          return true
        }
      }
    },
    mounted () {
      var user = sessionStorage.getItem('user')
      if (user) {
        user = JSON.parse(user)
        this.loginType = user.type
      }
      if (this.productIdConfig > 0) {
        var para = {
          productId: this.productIdConfig,
          type: this.loginType
        }
        this.$http.post('/tour/web/productTourExtend/getById.htm', para).then(response => {
          var resBody = response.body
          if (resBody.isSuccess === 0) {
            this.productTourExtend = resBody.result
            if (this.productTourExtend === undefined) {
              this.productTourExtend = {
                productId: '',
                zyts: '',
                yqts: '',
                tgsm: ''
              }
            }
          }
        })
      }
    }
  }
</script>

<style lang="stylus" rel="stylesheet/stylus">

</style>
